#!/bin/sh
base=$(cd `dirname $0`; pwd)

source "$base/project.sh"

cd $base;

run_shell="$base/bin/${MAIN_FOLDER}"

function prepare() {
    if [ -n "$ISS_APP_ENV" ];then
        run_shell="$run_shell --env=$ISS_APP_ENV"
    fi

    if [ -n "$APOLLO_META_SERVER" ];then
        apollo_opts="--apollo-url=http://$APOLLO_META_SERVER"
        run_shell="$run_shell $apollo_opts"
    fi

    if [ -n "$ISS_PROJECT_TAG" ];then
        run_shell="$run_shell --layer=$ISS_PROJECT_TAG"
    fi
}

function start() {

    DAEMON_MODE=${DAEMON_MODE:-true}
    if [ "x$DAEMON_MODE" = "xtrue" ];then
        nohup $run_shell > nohup.out 2>&1 &
        chmod 755 nohup.out
    else
        exec $run_shell
    fi
}

prepare
start
